package com.pet.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.pet.system.controller.vo.PackageserviceVo;
import com.pet.system.entity.Packageservice;
import com.pet.system.mapper.PackageserviceMapper;
import com.pet.system.service.PackageserviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class PackageserviceServiceImpl implements PackageserviceService {
    @Autowired
    private PackageserviceMapper packageserviceMapper;

    @Override
    public Packageservice getInfo(Long id) {
        return packageserviceMapper.selectById(id);
    }

    @Override
    public PageInfo<Packageservice> getPageList(PackageserviceVo packageservice) {
        LambdaQueryWrapper<Packageservice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtil.isNotEmpty(packageservice.getName()),Packageservice::getName,packageservice.getName());

        return PageHelper.startPage(packageservice.getPageNo(), packageservice.getPageSize())
                .doSelectPageInfo(() -> packageserviceMapper.selectList(queryWrapper));
    }

    @Override
    public int remove(Long[] packageserviceIds) {
        for (Long id : packageserviceIds) {
            int i = packageserviceMapper.deleteById(id);
        }
        return 1;
    }

    @Override
    public int edit(Packageservice packageservice) {
        return packageserviceMapper.updateById(packageservice);
    }

    @Override
    public int add(Packageservice packageservice) {
        return packageserviceMapper.insert(packageservice);
    }
}
